#ifndef RRMATH_H
#define RRMATH_H

#include <cmath>

class RRVec3
{
public:
    float x;
    float y;
    float z;
};

RRVec3 RRNormalize(RRVec3 arg)
{
    float len;
    RRVec3 v;
    len = sqrtf(arg.x * arg.x + arg.y * arg.y + arg.z * arg.z);
    v.x = arg.x / len;
    v.y = arg.y / len;
    v.z = arg.z / len;

    return v;
}

int CalcNorm(float p1[], float p2[], float p3[], float n[])
{
    float v1[3];
    float v2[3];
    float cross[3];
    float length;
    int i;

    for (i = 0; i < 3; i++)
        v1[i] = p1[i] - p2[i];

    for (i = 0; i < 3; i++)
        v2[i] = p3[i] - p2[i];

    for (i = 0; i < 3; i++)
        cross[i] = v2[(i+1)%3] * v1[(i+2)%3] -  v2[(i+2)%3] * v1[(i+1)%3];

    length = sqrtf(cross[0] * cross[0] + cross[1] * cross[1] + cross[2] * cross[2]);

    if (length == 0.0f)
        return 0;

    for (i = 0; i < 3; i++)
        n[i] = cross[i] / length;

    return 1;
}



#endif // RRMATH_H
